//
//  BaseNavigationController.m
//  PersonalOC
//
//  Created by 韩琴 on 2018/8/21.
//  Copyright © 2018年 韩琴. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) { // 非根控制器
        
        
//        [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"云"] forBarMetrics:UIBarMetricsDefault];
//        [self wr_setNavBarBackgroundAlpha:1];
        
        // 非根控制器才需要设置返回按钮
        // 设置返回按钮
        
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [backButton setTitle:@"" forState:UIControlStateNormal];
        [backButton setImage:[UIImage imageNamed:@"返回按钮"] forState:UIControlStateNormal];
        [backButton setImage:[UIImage imageNamed:@"返回按钮"] forState:UIControlStateHighlighted];
        [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        
        [backButton sizeToFit];
        backButton.frame = CGRectMake(0, 0, 35, 35);
        
        // 注意:一定要在按钮内容有尺寸的时候,设置才有效果
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,0);
        
        // 设置返回按钮
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        
    }
    // 这个方法才是真正执行跳转
    [super pushViewController:viewController animated:animated];
}
- (void) back{
    [self popViewControllerAnimated:true];
}

@end
